package com.smarttourism.service.impl;

import com.smarttourism.domain.Bill;
import com.smarttourism.mapper.BillMapper;
import com.smarttourism.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;
import java.util.UUID;

@Service
public class BillServiceImpl implements BillService {
    @Autowired
    private BillMapper billMapper;

    @Override
    public int add(Bill bill) {
//        计算税额
        bill.setRetemoney(bill.getMoney()*0.03);
        Random random = new Random();
//用UUID生成随机数并保留10位
        UUID uuid = UUID.randomUUID();
        bill.setBillNum(uuid.toString().replace("-","").substring(0,10));
//        随机生成0-9的7位数作为bill实例的num
        bill.setNum(String.valueOf(random.nextInt(10000000)));



        return billMapper.insert(bill);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return billMapper.deleteBatch(ids);
    }

    @Override
    public List<Bill> findAll(String pname,String billNum) {
        return billMapper.selectAll(pname,billNum);
    }
}
